#include "sqlite.hpp"
#include <cassert>

int select_callback(void *arg, int col, char **result, char **fields_name)
{
    std::vector<int> *vec = static_cast<std::vector<int>*>(arg);
    vec->push_back(std::stoi(result[0]));
    return 0;
}


int main()
{
    SqliteHelper helper("./test.db");

    // 创建 / 打开
    helper.open();

    // 新建数据库
    const char *ct = "create table if not exists student(sn int primary key, name varchar(32), age int);";
    assert(helper.exec(ct, nullptr, nullptr));

    // 新建数据库并插入
    helper.exec("create table test_1 (id varchar(30) primary key, age int not null);", nullptr, nullptr);
    helper.exec("insert into test_1 values('aaa', 10);", nullptr, nullptr);
    helper.exec("insert into test_1 values('bbb', 11);", nullptr, nullptr);
    helper.exec("insert into test_1 values('ccc', 12);", nullptr, nullptr);

    // 删除数据库
    helper.exec("delete from test_1 where age = 12;", nullptr, nullptr);

    // 查询数据库
    std::vector<int> vec;
    helper.exec("select age from test_1;", select_callback, &vec);
    for (auto e : vec)
    {
        std::cout << e << std::endl;
    }
    helper.close();

    return 0;
}